package com.kede.app.rest;

import com.kede.annotation.Log;
import com.kede.app.domain.SupplieStoreLog;
import com.kede.app.service.SupplieStoreLogService;
import com.kede.app.service.dto.SupplieStoreLogQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author Pr.li
* @date 2023-06-06
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "supplieStoreLog管理")
@RequestMapping("/api/supplieStoreLog")
public class SupplieStoreLogController {

    private final SupplieStoreLogService supplieStoreLogService;

    /**
     * 导出数据
     **/
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('supplieStoreLog:list')")
    public void exportSupplieStoreLog(HttpServletResponse response, SupplieStoreLogQueryCriteria criteria) throws IOException {
        supplieStoreLogService.download(supplieStoreLogService.queryAll(criteria), response);
    }

    /**
    * 查询supplieStore
    **/
    @GetMapping
    @ApiOperation("查询supplieStore")
    @PreAuthorize("@el.check('supplieStoreLog:list')")
    public ResponseEntity<Object> querySupplieStoreLog(SupplieStoreLogQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(supplieStoreLogService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
    * 新增supplieStore
    **/
    @PostMapping
    @Log("新增supplieStoreLog")
    @ApiOperation("新增supplieStoreLog")
    @PreAuthorize("@el.check('supplieStoreLog:add')")
    public ResponseEntity<Object> createSupplieStoreLog(@Validated @RequestBody SupplieStoreLog resources){
        return new ResponseEntity<>(supplieStoreLogService.create(resources),HttpStatus.CREATED);
    }


    /**
    * 修改supplieStore
    **/
    @PutMapping
    @Log("修改supplieStoreLog")
    @ApiOperation("修改supplieStoreLog")
    @PreAuthorize("@el.check('supplieStoreLog:edit')")
    public ResponseEntity<Object> updateSupplieStoreLog(@Validated @RequestBody SupplieStoreLog resources){
        supplieStoreLogService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


    /**
    * 删除supplieStore
    **/
    @DeleteMapping
    @Log("删除supplieStoreLog")
    @ApiOperation("删除supplieStoreLog")
    @PreAuthorize("@el.check('supplieStoreLog:del')")
    public ResponseEntity<Object> deleteSupplieStoreLog(@RequestBody Integer[] ids) {
        supplieStoreLogService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}